package com.qf.flying;

import java.awt.image.BufferedImage;
import java.util.Arrays;
/**
 * 此文件中新增的部分为潘首丞所写
* */
public class Hero extends FlyObject{
	//射速，越小越快，默认30
	private int life;//生命
	private int doubleFire;//双倍火力
	public BufferedImage image;//英雄图片
	public int score;//分数
	public int shootSpeed;
	public int bulletSpeed;//英雄对子弹速度的附加值，子弹的实际速度等于子弹本身的速度加这个
	public int bulletNumbers;//一次发射的子弹数量
	public int bulletType;
	
	public Hero() {
		shootSpeed = 30;
		bulletNumbers = 1;
		bulletSpeed = 0;
		bulletType = 1;

		image=ShootGame.heroImg;//图片
		width=image.getWidth();//宽
		height=image.getHeight();//高
		x=150;//x坐标
		y=400;//y坐标
		image=ShootGame.heroImg;
		doubleFire=0;//单倍活力
		life=3;//3条命
	}

	//开火   
	public Bullet[] fire(){
		int xStep=this.width/4;
		int bulletCenterDistance = width/(bulletNumbers + 1);
		Bullet[] bullets={};

		for (int i = 1; i <= bulletNumbers; i++)
		{
			//判断生成子弹的类型
			Bullet b = null;
			if (bulletType == 1)
			{
				b = new Bullet(x + bulletCenterDistance * i, y);
			}
			else if (bulletType == 2)
			{
				b = new Fire2(x + bulletCenterDistance * i, y);
			}
			else
			{
				b = new Fire3(x + bulletCenterDistance * i, y);
			}
			b.x -= b.image.getWidth()/2;
			b.y -= b.image.getHeight();
			b.Yspeed = b.Yspeed + bulletSpeed;
			bullets = Arrays.copyOf(bullets, bullets.length + 1);
			bullets[bullets.length - 1] = b;
		}
		return bullets;

	}
	
	//英雄计步器
	int index;
	@Override
	public void step() {
//		image=images[(index++/10)%2];
		
	}

	@Override
	public boolean isShot(Bullet b)
	{
		return false;
	}

	//移动到
	public void moveTo(int x,int y){
		this.x=x-width/2;
		this.y=y-height/2;
	}

	//添加火力
	public void addFire(){
		this.doubleFire+=20;
	}
	//加命
	public void addLife(){
		this.life+=1;
	}
	//获取生命数值
	public int getLife(){
		return life;
	}
	//生命减一
	public void subtractLife(){
		this.life--;
	}
	//火力归零
	public void setDoubleFire(){
		this.doubleFire=0;
	}

	public void noMoreAward()
	{
		shootSpeed = 30;
		bulletSpeed = 0;
		bulletNumbers = 1;
		bulletType = 1;
	}

	public void beAwarded(Award award)
	{
		life += award.life;
		bulletNumbers = award.bulletNumbers + 1 > bulletNumbers ?  award.bulletNumbers + 1 : bulletNumbers;
		bulletSpeed += award.bulletSpeed;
		shootSpeed = 30 - award.shootSpeed < shootSpeed ? 30 - award.shootSpeed : shootSpeed;
		bulletType = award.bulletType > bulletType ? award.bulletType : bulletType;
	}
	
	//被敌方撞击的方法
	public boolean hit(FlyObject other){
		int x1=other.x-this.width/2;
		int x2=other.x+other.width+this.width/2;
		int y1=other.y-this.height/2;
		int y2=other.y+other.height+this.height/2;
		
		int heroX=this.x+this.width/2;
		int heroY=this.y+this.height/2;
		return heroX>x1 &&heroX<x2 && heroY>y1 && heroY<y2;
	}
	
}
